// Cell 0 - First waypoint.
// Cell 1 - Num. of waypoints.
// Cell 2, 3 - SDF set to 1 if killed.
// Cell 4 - talknode.
begincreaturescript;
variables;

int job, status = 0;

body;
beginstate INIT_STATE;
       if ((get_memory_cell(2) != 0) || (get_memory_cell(3) != 0))
           if (get_flag(get_memory_cell(2), get_memory_cell(3)) == 1)
               erase_char(ME);
break;
beginstate DEAD_STATE;
       if ((get_memory_cell(2) != 0) || (get_memory_cell(3) != 0)) {
              set_flag(get_memory_cell(2), get_memory_cell(3), 1);
              }
break;
beginstate START_STATE;
       if (status <= get_memory_cell(1)) {
              job = approach_waypoint(ME, get_memory_cell(0) + status, 1);
              if (job == 1) {
                     stop_moving(ME);
                     status = status + 1;
                     }
              }
       // if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 2)
			set_state(3);
			else set_target(ME,-1);
		}
	
	// Look for a target, attack it if visible
	if (select_target(ME,1,0)) {
		do_attack();
		set_state(3);
		}
		
	// Have I been hit? Strike back!
	if (who_hit_me() >= 0) {
		set_target(ME,who_hit_me());
		do_attack();
		set_state(3);
		}
    if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;
beginstate 3;
       if (target_ok() == FALSE)
		    set_state(START_STATE);
       do_attack();
break;
beginstate TALKING_STATE;
       if (get_memory_cell(4) != 0) {
              begin_talk_mode(get_memory_cell(4));
              }
       else print_str("Talking: No response.");
break;